import { getItem } from '@/utils/storage'
import { isArray } from 'lodash-es'

const useBtnPermission = () => {
  const actionList = getItem('actionList') || []
  const hasPermission = (currentPerm: string | string[]) => {
    if (isArray(currentPerm)) {
      for (let i = 0; i < actionList.length; i++) {
        const action = actionList[i]
        if (!actionList.includes(action)) {
          return false
        }
      }
      return true
    } else if (typeof currentPerm === 'string') {
      if (!actionList.includes(currentPerm)) {
        return false
      }
      return true
    }
    return false
  }

  return { hasPermission }
}

export default useBtnPermission
